


exports.index = function(req, res){
res.render('index', { title: 'Index' });
};
exports.partials = function(req, res){
var name = res.params.name;
res.render('partials/'+ name);
};
exports.login = function(req, res){
res.render('login', { title: 'Login'});
};

exports.doLogin = function(db){

    return function(req, res) {
        var collection = db.get('usercollection');
        collection.findOne({"username":req.body.username,"password":req.body.password},function(e,query){
            if(query!=null){
            res.render('home', {
                "result" : query
            });
          }else{res.render('login', { title: 'Login'});}      
      
     });
       
    };

    };



exports.addInfo = function(db) {
    return function(req, res) {
        // Get our form values. These rely on the "name" attributes
        var title = req.body.title;
        var content = req.body.content;
        // Set our collection
        var collection = db.get('usercollection');
        // Submit to the DB
        collection.insert({
            "title" : title,
            "content" : content
        }, function (err, doc) {
            if (err) {
                // If it failed, return error
                res.send("There was a problem adding the information to the database.");
            }
            else {
                // If it worked, set the header so the address bar doesn't still say /adduser
                res.location("userlist");
                // And forward to success page
                res.redirect("userlist");
            }
        });
    };
};



exports.logout = function(req, res){
res.redirect('/');
};
exports.home = function(req, res){
res.render('home', { title: 'Home'});
};